//
//  GrantListViewController.m
//  FactorySale
//
//  Created by 主事丫环 on 2020/3/26.
//  Copyright © 2020 主事丫环. All rights reserved.
//
/**
 这个控制器是一个父控制器，下面三个为同一个子控制器
 */
#import "GrantListViewController.h"
#import "GrantlistContentViewController.h"
#import "SGPagingView.h"

@interface GrantListViewController ()<SGPageTitleViewDelegate, SGPageContentScrollViewDelegate>
@property (nonatomic, strong) SGPageTitleView *pageTitleView;
@property (nonatomic, strong) SGPageContentScrollView *pageContentScrollView;

@end

@implementation GrantListViewController
- (void)viewWillAppear:(BOOL)animated {

    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:animated];
  
}
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:animated];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"补助金";
    if ([self.from isEqualToString:@"tabbar"]) {
        
    } else {
        
    }
    [self showNav];
}
-(void)showNav{
    
    SGPageTitleViewConfigure *configure = [SGPageTitleViewConfigure pageTitleViewConfigure];
    configure.indicatorAdditionalWidth = 10; // 说明：指示器额外增加的宽度，不设置，指示器宽度为标题文字宽度；若设置无限大，则指示器宽度为按钮宽度
    configure.titleGradientEffect = YES;
    
    configure.titleSelectedColor= [UIColor colorWithHexString:@"#31CEA9"];
    configure.titleColor= [UIColor colorWithHexString:@"#999999"];
    configure.showIndicator = YES;
    configure.indicatorColor = zhutiColor;
    configure.bottomSeparatorColor= [UIColor whiteColor];
    
    NSMutableArray *titleArr = [NSMutableArray arrayWithCapacity:1];
    NSMutableArray *childVCS = [NSMutableArray arrayWithCapacity:1];
    [titleArr addObject:@"       全部            |"];
    [titleArr addObject:@"     处理中          |"];
    [titleArr addObject:@"   历史记录     "];
    
    for (int i = 0; i<titleArr.count; i++) {
        GrantlistContentViewController *oneVC = [[GrantlistContentViewController alloc] init];
        oneVC.from = self.from;
        oneVC.type = [NSString stringWithFormat:@"%d",i];
        [childVCS addObject:oneVC];
    }
    
    self.pageTitleView = [SGPageTitleView pageTitleViewWithFrame:CGRectMake(0, kNaviHeight, KWIDTH, 0) delegate:self titleNames:titleArr configure:configure];
    self.pageTitleView.indicatorView.hidden = YES;
    
    self.pageContentScrollView = [[SGPageContentScrollView alloc] initWithFrame:CGRectMake(0, kNaviHeight+44, KWIDTH, KHEIGHT-kNaviHeight-44) parentVC:self childVCs:childVCS];
    
    _pageContentScrollView.delegatePageContentScrollView = self;
//    [self.view addSubview:self.pageTitleView ];
    
    [self.view addSubview:_pageContentScrollView];
    
}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    [super textFieldShouldReturn:textField];
    return YES;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [super textFieldShouldReturn:textField];
    //    SearchResultController *vc = [SearchResultController new];
    //    vc.keyword = textField.text;
    //    vc.Ctype = @"0";
    //    [self.navigationController pushViewController:vc animated:YES];
    return YES;
}

- (void)pageTitleView:(SGPageTitleView *)pageTitleView selectedIndex:(NSInteger)selectedIndex {
    [self.pageContentScrollView setPageContentScrollViewCurrentIndex:selectedIndex];
}

- (void)pageContentScrollView:(SGPageContentScrollView *)pageContentScrollView progress:(CGFloat)progress originalIndex:(NSInteger)originalIndex targetIndex:(NSInteger)targetIndex {
    [self.pageTitleView setPageTitleViewWithProgress:progress originalIndex:originalIndex targetIndex:targetIndex];
}

- (void)pageContentScrollView:(SGPageContentScrollView *)pageContentScrollView index:(NSInteger)index {
    if (index == 1 || index == 3) {
        [_pageTitleView removeBadgeForIndex:index];
    }
}

@end
